from Tkinter import *
from servicios.Functions import *
from servicios.Persistense import Persistense
from ThreadSerieChecker import ThreadSerieChecker
from FrameListGeneric import FrameListGeneric

class FrameSeriesStatus(FrameListGeneric):

        _threads = []
        _series = []
        
	def __init__(self,master=None):
            FrameListGeneric.__init__(self,master)

	def load_items(self):
            series_data = Persistense.instance().get_series()

            self._threads = []
            self._series = []

            try:
                for item in series_data.values():
                    t = ThreadSerieChecker(item['id'],self._series)
                    t.start()
                    self._threads.append(t)

                for t in self._threads:
                    t.join()

                self._list = sorted(self._series,key=lambda s: s[1])
                
            except Exception,e:
                print e
